import vuex from "vuex"
import vue from 'vue'
import userInfo from './userInformation'
import createPersistedState from 'vuex-persistedstate'


vue.use(vuex)

const store = new vuex.Store({
    state:{
        num:0,
        num1:0,
        studentList:[
            {
                id:'11',
                name: '的撒旦',
                age: '17',
                phone: '15344433392',
                idCard: '433127200611036682',
                address: '上海市普陀区金沙江路 1518 弄',
                vaccine: 1,//1代表接种  0代表未接种
                only  : 1,//1代表独生  0代表非独生
                hk: 1,//1代表城市户口 0代表农村
            },
            {
                id:'18',
                name: '没',
                age: '27',
                phone: '13256776598',
                idCard: '430312060646462266',
                address: '上海市普陀区金沙江路 1518 弄',
                vaccine: 1,//1代表接种  0代表未接种
                only  : 1,//1代表独生  0代表非独生
                hk: 1,//1代表城市户口 0代表农村
            },
            {
                id:'23',
                name: '烦恼',
                age: '37',
                phone: '18876843543',
                idCard: '4331206644422352634',
                address: '上海市普陀区金沙江路 1518 弄',
                vaccine: 1,//1代表接种  0代表未接种
                only  : 1,//1代表独生  0代表非独生
                hk: 1,//1代表城市户口 0代表农村
            },
        ]
    },
    mutations:{
        addNum(state, arg){
            state.num += arg
        },
        changeNum(state, arg){
            state.num = arg
        }
    },
    actions:{
        asyncChangeNum(store,arg){
            this.state.num += arg
           // store.commit('changeNum',arg)
        }
    },
    getters:{
        aloneCount(a){
            return a.studentList.reduce((total,item)=>item.only==='1'?total+1:total,0);
        },
        cityCount(a){
            return a.studentList.reduce((total,item)=>item.hk==='1'?total+1:total,0);
        },
        vaccineCount(a){
            return a.studentList.reduce((total,item)=>item.vaccine==='1'?total+1:total,0);
        },
        ageCount(a){
            return a.studentList.reduce((total,item)=>item.age>=18?total+1:total,0);
        },

    },

    modules:{
        userInfo
    },
    plugins:[createPersistedState()],
})
export default store